package com.csdj.controller;

import com.csdj.pojo.User;
import com.csdj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value ="/addUsers")
    public ModelAndView addUser(){
        ModelAndView mv=new ModelAndView();
        User user = new User();
        user.setName("张小小");
        user.setAge(18);
        user.setEmail("zxx@163.com");
        int row=userService.addUser(user);
        if(row>0){
            mv.addObject("msg","添加成功");
        }else{
            mv.addObject("msg","添加失败");
        }
        mv.setViewName("success");
        return mv;
    }

    @RequestMapping(value ="/deleteUsers")
    public ModelAndView deleteUser(){
        ModelAndView mv=new ModelAndView();
        int row=userService.deleteUser(7);
        if(row>0){
            mv.addObject("msg","删除成功");
        }else{
            mv.addObject("msg","删除失败");
        }
        mv.setViewName("success");
        return mv;
    }
}
